package com.lxyk.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lxyk.pojo.Salary;
import com.lxyk.service.SalaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @ClassName SalaryContrller
 * @Description TODO
 * @Author FJQ
 * @Date 2022/10/26 15:07
 * @Version 1.0
 **/
@Controller
@RequestMapping("/salary")
@Slf4j
public class SalaryController {

    @Autowired
    private SalaryService salaryService;

    @RequestMapping("/searchCalcSalay")
    public String searchCalcWorkerSalary(String startDate,String endDate,Model model,
                                         @RequestParam(required = false,defaultValue = "1",value = "pageNum")Integer pageNum,
                                         @RequestParam(defaultValue = "10",value = "pageSize")Integer pageSize) {
        if(pageNum <=0 || pageNum.equals("") ||pageNum == null){
            pageNum = 1;
        }
        if(pageSize <= 0 || pageNum.equals("") || pageSize == null){
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Salary> pageInfo = salaryService.calcSalaryByCondition(startDate,endDate,pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("startDate",startDate);
        model.addAttribute("endDate",endDate);
        return "salaryList";
    }

    @RequestMapping("/searchSalay")
    public String searchCalcWorkerSalary(Model model,
                                         @RequestParam(required = false,defaultValue = "1",value = "pageNum")Integer pageNum,
                                         @RequestParam(defaultValue = "10",value = "pageSize")Integer pageSize) {
        if(pageNum <=0 || pageNum.equals("") ||pageNum == null){
            pageNum = 1;
        }
        if(pageSize <= 0 || pageNum.equals("") || pageSize == null){
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Salary> pageInfo = salaryService.calcSalary(pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "salaryList";
    }

    @RequestMapping("/IsNullWorker")
    public String IsNullWorker(Model model,
                                         @RequestParam(required = false,defaultValue = "1",value = "pageNum")Integer pageNum,
                                         @RequestParam(defaultValue = "10",value = "pageSize")Integer pageSize) {
        if(pageNum <=0 || pageNum.equals("") ||pageNum == null){
            pageNum = 1;
        }
        if(pageSize <= 0 || pageNum.equals("") || pageSize == null){
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<Salary> pageInfo = salaryService.IsNullWorker(pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "salaryList";
    }

}
